$(function(){
    //首页找课程根据一级分类查询课程
    $(".cat_tag ul li").mouseenter(function (){
        var dataId = $(this).attr("data-id");
        //发送ajax请求，向后端传一个分类id，后端把查询的数据返回给前端
        $.ajax({
            type:"get",
            url:"/queryIndexCourse",
            async:false,
            data:{
                "dataId" : dataId
            },
            success:function(data){
                console.log(data);
                console.log(typeof(data));
                var htm = ' ';
                htm += '<div class="left_pro">\n' ;
                htm +=    '       <dl>\n' ;
                htm +=    '        <dt> \n' ;
                htm +=    '         <a title="' + data[0].courseName + '" th:href="@{\'/courseDetail?courseId=\' + ${course.id}}" target="_blank"> <img alt="' + data[0].courseName + '" data-original="' + data[0].cover + '" class="lazy" src="' + data[0].cover + '" /></a>\n' ;
                htm +=    '         <a class="list_title" th:href="@{\'/courseDetail?courseId=\' + ${course.id}}" target="_blank" >' + data[0].courseName + '</a>\n' ;
                htm +=    '         <span class="s1"><a title="' + data[0].teacher + '" class="list_name" href="#" target="_blank" rel="nofollow" >' + data[0].teacher + '</a></span>\n' ;
                htm +=    '         <span style="float:right;"><span class="pri_normal pri_dispay">¥<em>' + data[0].price + '</em></span></span>\n' ;
                htm +=    '        </dt> \n' ;
                htm +=    '       </dl> \n' ;
                htm +=    '      </div> ';
                htm += ' <div class="right_pro"> \n' ;
                for(var i = 1; i < data.length; i++){
                        htm +=    '       <dl>\n' ;
                        htm +=    '        <dt> \n' ;
                        htm +=    '         <a title="' + data[i].courseName + '" th:href="@{\'/courseDetail?courseId=\' + ${course.id}}" target="_blank"> <img alt="' + data[i].courseName + '" data-original="' + data[i].cover + '" class="lazy" src="' + data[i].cover + '" /></a>\n' ;
                        htm +=    '         <a class="list_title" th:href="@{\'/courseDetail?courseId=\' + ${course.id}}" target="_blank" >' + data[i].courseName + '</a>\n' ;
                        htm +=    '         <span class="s1"><a title="' + data[i].teacher + '" class="list_name" href="#" target="_blank" rel="nofollow" >' + data[i].teacher + '</a></span>\n' ;
                        htm +=    '         <span style="float:right;"><span class="pri_normal pri_dispay">¥<em>' + data[i].price + '</em></span></span>\n' ;
                        htm +=    '        </dt> \n' ;
                        htm +=    '        <dd style="transition: all 0.5s"> \n' ;
                        htm +=    '         <a title="' + data[i].courseName + '" th:href="@{\'/courseDetail?courseId=\' + ${course.id}}" target="_blank"> <p><img height="100px" widht="100px" onerror="this.src=\'images/404.jpg\'" data-original="http://face.yingsheng.com/files/251/101627/101627_100_100.jpg?rnd=1019134630" class="lazy img_01" src="http://face.yingsheng.com/files/251/101627/101627_100_100.jpg?rnd=1019134630" alt="' + data[i].teacher + '" /><span>' + data[i].teacher + '</span> </p> <p>' + data[i].intro + '</p> <p class="li_go">去听课<img class="img_02" src="images/go_gif.gif" alt="go" /></p></a>\n' ;
                        htm +=    '        </dd> \n' ;
                        htm +=    '       </dl> \n' ;
                }
                htm +=    '      </div> ';

                $("#course_").html(htm);
                //鼠标进入切换样式
                $("#course_ .right_pro dl").mouseenter(function (){
                    $(this).find("dd").css({
                        'left':0,'top':0,'width':'198px','padding':'16px 12px'
                    });
                    console.log("success");
                });
                //鼠标移出切换样式
                $("#course_ .right_pro dl").mouseleave(function (){
                    $(this).find("dd").css({
                        'transition': 'all 0.5s','left':'230px','top':0,'width':0,'padding':'16px 0px'
                    });
                    console.log("success");
                });
            }


        });
    });
    //点击新闻分类切换新闻
    $(".tabTop ul li").click(function (){
        var value = $(this).text();
        $.ajax({
            type: "get",
            url: "/queryIndexNews",
            async: false,
            data: {
                "value": value
            },
            success: function (data) {
                console.log(data);
                var htm = '';
                for(var i = 0; i < 5; i++){
                    htm += '     <ul>\n' ;
                    for(var j = 0; j < 5; j++){
                        var index = (5 * i + (j + 1)) - 1 ;
                        console.log(data[index].title);
                        htm += '      <li><a target="_blank" href="/pxzx-zjwz/144087.html">' + data[index].title + '</a></li>\n' ;
                    }
                    htm += '     </ul>\n' ;
                }
                $("#p_").html(htm);


            }
        });
    });

})




